package ldkxingzhe.ldkxingzhedemo.menu;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import ldkxingzhe.ldkxingzhedemo.R;


/**
 * Created by liangdengke on 2015/8/21.
 */
public class ContextualMenuActivity extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_context_menu);
        ListView listView = (ListView)findViewById(R.id.list_view);
        String name[] = new String[]{"1","2","45445f","545456","jfdjfj"};
        ArrayAdapter adapter = new ArrayAdapter(this,R.layout.list_view_context_menu,R.id.text,name);
        listView.setAdapter(adapter);
        registerForContextMenu(listView);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.option_menu,menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        Log.d("TAG","item.getItemId = " + item.getItemId());
        AdapterView.AdapterContextMenuInfo contextMenuInfo = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
        Log.d("TAG","contextMenuInfo.id = " + contextMenuInfo.id);
        return super.onContextItemSelected(item);
    }
}
